const {
  REQUEST,
  transformRequestSendDefault
} = require('miniprogram-request')

REQUEST.Defaults.baseURL = ""
REQUEST.Defaults.retry = 2
REQUEST.Defaults.loading = false

/**
 * 请求拦截
 * @param {*} options 
 */
REQUEST.Defaults.transformSend = async (options) => {
  console.log('请求拦截')
  if(options.loading){
    wx.showLoading({
      title: '加载中...',
    })
  }
  return transformRequestSendDefault(options);
};

/**
 * 响应拦截
 */
REQUEST.Defaults.transformResponse = async (res,options) => {
  console.log('响应拦截')
  if(options.loading){
   wx.hideLoading()
  }
  res = res.data
  if (res.status == 200) {
    return res
  }else{
    // return Promise.reject(res.data.msg)
  }
};

module.exports = {
  http: REQUEST
}